package com.zhq.zhq_blog.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zhq.zhq_blog.entity.Comment;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 *  评论Mapper接口
 */
@Repository
public interface CommentMapper extends BaseMapper<Comment> {

    //查询评论的所有回复
    @Results(id = "commentResultMap",value = {
            @Result(property = "id",column = "id"),
            @Result(property = "replyList",column = "id", one = @One(select = "com.zhq.zhq_blog.mapper.ReplyMapper.queryAllReply"))
    })
    @Select("SELECT * FROM tb_comment WHERE tb_comment.id = #{comment_id}")
    Comment queryComment(@Param("comment_id") Integer comment_id);

    @ResultMap(value = "commentResultMap")
    @Select("SELECT * from tb_comment where tb_comment.blog_id = #{blog_id}")
    List<Comment> queryCommentList(@Param("blog_id") Integer blog_id);

}
